package com.jww.cloud.auth.config.error;

import com.jww.common.web.util.ResultUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
import org.springframework.security.oauth2.provider.error.DefaultWebResponseExceptionTranslator;
import org.springframework.stereotype.Component;

@Component
public class JwwWebResponseExceptionTranslator extends DefaultWebResponseExceptionTranslator {

    @Override
    @SuppressWarnings("unchecked")
    public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception {
        ResponseEntity responseEntity = super.translate(e);
        return new ResponseEntity(ResultUtil.fail(responseEntity.getStatusCode().value(), e.getMessage()), responseEntity.getStatusCode());
    }
}
